$(function () {
    $("#gradeTable").bootstrapTable({
        method: "get",
        contentType: "application/json",
        url: "/inputmanagerController/getGatherstoreTagGreater2",
        // striped: true,
        pageNumber: 1,
        pagination: true,
        sidePagination: 'server',
        pageSize: 5,
        pageList: [1, 3, 5, 7],
        queryParams: function (parmes) {
            return {
                pageNum: (parmes.offset / parmes.limit) + 1,
                pageSize: parmes.limit,
                storer: $("#storer").val(),
                gatherId: $("#gatherId").val(),
                registerTime: $("#registerTime").val(),
                checker: $("#checker").val(),
                checkTag: $('input[name="checkTag"]:checked').val(),
            }
        },
        columns: [
            {title: "申请单编号", field: 'gatherId', align: "center",
                formatter: function (value, row, index) {
                    console.log(row)
                    return "<a href='#' class='ckxq' onclick='ckxq("+JSON.stringify(row)+")'>"+value+"</a>"
                }},
            {title: "入库理由", field: 'reason', align: "center"},
            {title: "完成时间", field: 'checkTime', align: "center",
                formatter: function (value, row, index) {
                 if(value==undefined){
                     return "未完成"
                 }else {
                     return value
                 }
                }},
            {title: "应入总件数", field: 'amountSum', align: "center"},
            {title: "已入总件数", field: 'gatheredAmountSum', align: "center",
                formatter: function (value, row, index) {
                    if(value==undefined){
                        return "0.00"
                    }else {
                        return value
                    }
                }},
            {title: "入库单状态", field: 'storeTag', align: "center",
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return "<font color=\"orange\">等待</font>"
                    }
                    if (value == 2 || value == 3) {
                        return "<font color=\"red\">执行</font>"
                    }
                    if (value == 4) {
                        return "<font color=\"green\">完成</font>"
                    }
                }},
            // {
            //     title: "审核", field: 'gatherId', align: "center",
            //     formatter: function (value,row,index) {
            //         var btn1 = "<button class=\"btn btn-success btn-sm\" onclick='updateGrede("+JSON.stringify(row)+")'>审核</button>";
            //         //var btn2 = "<button class=\"btn btn-secondary btn-sm\" data-toggle=\"modal\" onclick='deleteGrade("+value+")'>不通过</button>";
            //         return btn1 //+ btn2
            //     }
            // }
            //1  等待  2，3 执行  4完成
        ]
    })
    $("#condition").click(function () {
        $("#gradeTable").bootstrapTable("refresh")
    })
})
//查看详情
function ckxq(parse) {
    $("#two").show();
    $("#one").hide();
    $("#rkr").val(parse.storer);
    $("#rkly").val(parse.reason);
    $("#zjs").html(parse.amountSum);
    $("#zje").html(parse.costPriceSum);
    $("#djr").html(parse.register);
    $("#djsj").html(parse.registerTime);
    $("#bz").val(parse.remark);
    $.ajax({
        url:"/inputmanagerController/BysGatherIdquerysGatherDetails2",
        type:"get",
        contentType: "application/json",
        async:true,
        data:{
            id:parse.id,
        },
        success:function (list) {
            console.log(list)
            let content="";
            for (let i = 0; i < list.length; i++) {
                if(list[i].amountUnit==undefined){
                    list[i].amountUnit=""
                }
                if(list[i].productDescribe==undefined){
                    list[i].productDescribe=""
                }
                content += "<tr>" +
                    "<td>" + list[i].productName + "</td>" +
                    "<td>" + list[i].productId + "</td>" +
                    "<td>" + list[i].productDescribe + "</td>" +
                    "<td>" + list[i].amount + "</td>" +
                    "<td>" + list[i].amountUnit + "</td>" +
                    "<td>" + list[i].costPrice + "</td>" +
                    "<td>" + list[i].subtotal + "</td>" +
                    "</tr>"
            }
            $("#tbody").append(content)
        }
    })
}
function  fh() {
    $("#tbody").html("")
    $("#one").show();
    $("#two").hide();
}